package Demo1;

import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;

    public MyStack() {
        this.elem = new int[5];
    }

    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }


    public int pop() {

//1、判断栈不为空
        if(empty()){
            throw new ArrayIsEmptyException("pop元素时 数组为空");
        }
//2、开始删除
        return elem[--usedSize];

    }

    public boolean empty() {
        return usedSize == 0;
    }
}
